﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Ueyes.Common.Shell.Telerikk;
using Ueyes.Common.Core;
using Telerik.WinControls.UI.Docking;
using Telerik.WinControls.UI;

namespace UeyesAIS.Presentation
{
    public partial class AISView : ViewBase, IPagePlugin, IAISView
    {
        #region 接口实现
        public string DisplayName { get; set; }

        public Image ImageIcon { get; }

        public string PluginName { get; set; }
        public VMAISView Model { get; set; }
        #endregion

        private List<ImageGroup> _listImageGr;
        private string _selectName;
        private int _itemindex;
        private bool _allowClosing;
        private string _selpath;

        public AISView()
        {
            InitializeComponent();
            listView1.MultiSelect = false;
            listView1.LargeImageList = new ImageList();
            listView1.LargeImageList.ImageSize = new Size(100, 100);
            versionLabel.Text = ProductVersion.ToString();
            _listImageGr = new List<ImageGroup>();
        }



        public void LoasControl()
        {
            LoadDorkControl();
            InspEntity.Intance.MsgEvent += Intance_MsgEvent;
            InspEntity.Intance.ChangValue += Intance_ChangValue;
            operatorIDLabel.Text = Device.Parameter.CurentOperator;
        }
        private void LoadDorkControl()
        {
            try
            {
                _listImageGr.Clear();
                _allowClosing = true;
                radDock1.CloseAllWindows();
                _allowClosing = false;
                radRibbonBarButtonGroup10.Items.Clear();
                foreach (var c in Device.DeviceEntityControl.Cameras)
                {
                    if (c != null && !string.IsNullOrEmpty(c.CameraName))
                    {
                        var cs = new ImageGroup(c.CameraName);
                        cs.Name = c.CameraName;
                        radDock1.DockControl(cs, DockPosition.Top, DockType.ToolWindow);
                        cs.LoadData();
                        cs.IndexChanged += Cs_IndexChanged;
                        _listImageGr.Add(cs);
                        var cbe = new RadCheckBoxElement { Text = c.CameraName };
                        cbe.ToggleStateChanging += Cbe_ToggleStateChanging; ;
                        radRibbonBarButtonGroup10.Items.Add(cbe);
                    }
                }

                ImageManage.Instance.RefreshGroupItem += Instance_RefreshGroupItem;
                ImageManage.Instance.RefreshGroupResult += Instance_RefreshGroupResult;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
